Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Introduce write_labeled! template formatter macro #4539

Closed
wants to merge 1 commit into from

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Sep 26, 2024

Mainly an experiment to see if this looks more readable / uniform.

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

@Veykril Veykril force-pushed the veykril/push-zoouknwvtors branch from 66f0460 to e185b4f Compare September 26, 2024 09:37
@@ -384,14 +385,14 @@ fn write_modified_change_summary(
) -> Result<(), std::io::Error> {
writeln!(formatter, "Change {}", short_change_hash(change_id))?;
for commit in modified_change.added_commits.iter() {
formatter.with_label("diff", |formatter| write!(formatter.labeled("added"), "+"))?;
formatter.with_label("diff", |formatter| write_labeled!(formatter, "added", "+"))?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting one being nested. Could make the macro accept something like

Suggested change
formatter.with_label("diff", |formatter| write_labeled!(formatter, "added", "+"))?;
write_labeled!(formatter, "diff" & "added", "+")?;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

label string could be separated by whitespace (and split by formatter.labeled()), but I don't know if we like it.

@@ -775,12 +776,12 @@ fn print_error_sources(ui: &Ui, source: Option<&dyn error::Error>) -> io::Result
ui.stderr_formatter()
.with_label("error_source", |formatter| {
if err.source().is_none() {
write!(formatter.labeled("heading"), "Caused by: ")?;
write_labeled!(formatter, "heading", "Caused by: ")?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the original code because it's clearer which string literal is a label.

@@ -384,14 +385,14 @@ fn write_modified_change_summary(
) -> Result<(), std::io::Error> {
writeln!(formatter, "Change {}", short_change_hash(change_id))?;
for commit in modified_change.added_commits.iter() {
formatter.with_label("diff", |formatter| write!(formatter.labeled("added"), "+"))?;
formatter.with_label("diff", |formatter| write_labeled!(formatter, "added", "+"))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

label string could be separated by whitespace (and split by formatter.labeled()), but I don't know if we like it.

@PhilipMetzger
Copy link
Contributor

I personally don't like the macro variant, as it doesn't improve the readability of the code.

@Veykril
Copy link
Member Author

Veykril commented Sep 26, 2024

Fair, I am indifferent to the change so mainly opened it to see opinions.

@Veykril Veykril closed this Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants